package com.nowcoder.code.hjnc;

public class NC105 {

    public static void main(String[] args) {

//        int[] nums = {1, 1, 2, 3, 7, 7, 7, 9, 9, 10};
//        int[] nums = {1, 2, 2, 3, 4};
        int[] nums = {-2,1, 2};
//        int[] nums = {};
        System.out.println(new NC105().search(nums, 2));

    }


    public int search(int[] nums, int target) {
        if (nums.length == 0) {
            return -1;
        }
        if (nums[0] == target) {
            return 0;
        }
        int mid, start = 0, end = nums.length - 1;
        while (start <= end) {
            mid = start + (end - start) / 2;
            if (nums[mid] == target) {
                while (nums[mid] == target) {
                    mid--;
                }
                return mid + 1;
            }
            if (nums[mid] > target) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }
        }

        return -1;
    }

}
